package com.woniu.common;


import java.io.Serializable;

public class Result<T> implements Serializable {
    /**
     * 执行是否成功
     */
    private boolean success;
    /**
     * 结果码
     * 0000  成功
     * 0100  数据库失败
     * 1000  失败
     */
    private String code;

    /**
     * 详细信息
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;

    public Result() {
    }

    public Result(boolean success, String code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data=data;
    }
    public Result( T data) {
        this.success = true;
        this.code = "0000";
        this.message = "执行成功";
        this.data=data;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Result success(){
        return success(null);
    }
    public static Result success(Object data){
        return new Result(true,"0000","执行成功",data);
    }

    public static Result fail(String message ){
        return new Result(false,"1000",message,null);
    }

    public static Result fail(String code, String message ){
        return new Result(false,code,message,null);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "Result{" +
                "success=" + success +
                ", code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
